package com.turnengine.client.local.location.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Grid Details.
 */
public class GridDetails implements IGridDetails, Comparable<IGridDetails> {

	/** The start location id. */
	private int startLocationId = -1;
	/** The finish location id. */
	private int finishLocationId = -1;
	/** The owned. */
	private int owned = 0;
	/** The allied. */
	private int allied = 0;
	/** The hostile. */
	private int hostile = 0;

	/**
	 * Creates a new Grid Details.
	 */
	public GridDetails() {
	}

	/**
	 * Creates a new Grid Details.
	 * @param startLocationId the start location id
	 * @param finishLocationId the finish location id
	 * @param owned the owned
	 * @param allied the allied
	 * @param hostile the hostile
	 */
	public GridDetails(int startLocationId, int finishLocationId, int owned, int allied, int hostile) {
		setStartLocationId(startLocationId);
		setFinishLocationId(finishLocationId);
		setOwned(owned);
		setAllied(allied);
		setHostile(hostile);
	}

	/**
	 * Creates a new Grid Details.
	 * @param gridDetails the grid details
	 */
	public GridDetails(GridDetails gridDetails) {
		setStartLocationId(gridDetails.getStartLocationId());
		setFinishLocationId(gridDetails.getFinishLocationId());
		setOwned(gridDetails.getOwned());
		setAllied(gridDetails.getAllied());
		setHostile(gridDetails.getHostile());
	}

	/**
	 * Creates a new Grid Details.
	 * @param iGridDetails the i grid details
	 */
	public GridDetails(IGridDetails iGridDetails) {
		setStartLocationId(iGridDetails.getStartLocationId());
		setFinishLocationId(iGridDetails.getFinishLocationId());
		setOwned(iGridDetails.getOwned());
		setAllied(iGridDetails.getAllied());
		setHostile(iGridDetails.getHostile());
	}

	/**
	 * Returns the start location id.
	 * @return the start location id.
	 */
	public int getStartLocationId() {
		return startLocationId;
	}

	/**
	 * Returns the finish location id.
	 * @return the finish location id.
	 */
	public int getFinishLocationId() {
		return finishLocationId;
	}

	/**
	 * Returns the owned.
	 * @return the owned.
	 */
	public int getOwned() {
		return owned;
	}

	/**
	 * Returns the allied.
	 * @return the allied.
	 */
	public int getAllied() {
		return allied;
	}

	/**
	 * Returns the hostile.
	 * @return the hostile.
	 */
	public int getHostile() {
		return hostile;
	}

	/**
	 * Sets the start location id.
	 * @param startLocationId the start location id to set.
	 */
	public void setStartLocationId(int startLocationId) {
		this.startLocationId = startLocationId;
	}

	/**
	 * Sets the finish location id.
	 * @param finishLocationId the finish location id to set.
	 */
	public void setFinishLocationId(int finishLocationId) {
		this.finishLocationId = finishLocationId;
	}

	/**
	 * Sets the owned.
	 * @param owned the owned to set.
	 */
	public void setOwned(int owned) {
		this.owned = owned;
	}

	/**
	 * Sets the allied.
	 * @param allied the allied to set.
	 */
	public void setAllied(int allied) {
		this.allied = allied;
	}

	/**
	 * Sets the hostile.
	 * @param hostile the hostile to set.
	 */
	public void setHostile(int hostile) {
		this.hostile = hostile;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(709, 37);
		hash.append(startLocationId);
		hash.append(finishLocationId);
		hash.append(owned);
		hash.append(allied);
		hash.append(hostile);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GridDetails) {
			GridDetails compare = (GridDetails) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.startLocationId, compare.startLocationId);
			equals.append(this.finishLocationId, compare.finishLocationId);
			equals.append(this.owned, compare.owned);
			equals.append(this.allied, compare.allied);
			equals.append(this.hostile, compare.hostile);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGridDetails compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.startLocationId, compare.getStartLocationId());
		builder.append(this.finishLocationId, compare.getFinishLocationId());
		builder.append(this.owned, compare.getOwned());
		builder.append(this.allied, compare.getAllied());
		builder.append(this.hostile, compare.getHostile());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("startLocationId", startLocationId);
		string.append("finishLocationId", finishLocationId);
		string.append("owned", owned);
		string.append("allied", allied);
		string.append("hostile", hostile);
		return string.toString();
	}
}
